package servlet;

import java.io.IOException;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import news.*;

public class NewsServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		int nid = 1;
		try {
			nid = Integer.parseInt(request.getParameter("nid"));
		} catch (Exception e) {
		}
		News oneNews = NewsDao.dao.findOneNews(nid);
		request.setAttribute("oneNews", oneNews);
		List<Comments> comlist = CommentsDao.dao.findComments(nid);
		request.setAttribute("nid", nid);
		request.setAttribute("comlist", comlist);
		request.setAttribute("comSize", comlist.size());

		request.getRequestDispatcher("WEB-INF/jsp/news.jsp").forward(request,
				response);

	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
